package com.czk.stack;

import java.util.Stack;

/**
 *
 * 使用栈实现队列
 *
 * @Author:ChenZhangKun
 * @Date: 2023/7/11 12:07
 */
public class StackImpQueue<T> {

    private Stack<T> stackIn;
    private Stack<T> stackOut;

    public StackImpQueue(Stack<T> stackIn, Stack<T> stackOut) {
        this.stackIn = stackIn;
        this.stackOut = stackOut;
    }
    public void inQueue(T t){
        stackIn.push(t);
    }
    public T dequeue(){
        if (stackOut.isEmpty()){
            while (!stackIn.isEmpty()){
                stackOut.push(stackIn.pop());
            }
        }
        return stackOut.pop();
    }

    public static void main(String[] args) {
        StackImpQueue<Integer> stackImpQueue=new StackImpQueue<>(new Stack<>(),new Stack<>());

        stackImpQueue.inQueue(1);
        stackImpQueue.inQueue(2);

        System.out.println(stackImpQueue.dequeue());

        stackImpQueue.inQueue(3);

        System.out.println(stackImpQueue.dequeue());

    }

}
